package com.example.demo.幂等性控制.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @projectName:demo
 * @see:com.example.demo.幂等性控制.aop
 * @author:袁成龙
 * @createTime:2020/10/14 13:00
 * @version:1.0
 */
@Component
@Aspect
public class XianLiuAop {


    @Autowired
    private RedisTemplate<String,String> redisTemplate;



    @Pointcut("execution(public * com.example.demo.幂等性控制.controller.TestXianLiuController.*(..))")
    public void xianliu(){}


    @Around("xianliu() && @annotation(com.example.demo.幂等性控制.anniontion.XianLiu)")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        Long keyy = redisTemplate.opsForValue().increment("keyy", 1);
        if(keyy>3){
            redisTemplate.delete("keyy");
            return null;
        }else{
            return proceedingJoinPoint.proceed();
        }
    }

}